package es.unex.meigas.gui;

import java.awt.Component;

import javax.swing.JPanel;

import es.unex.meigas.core.DasocraticElement;

public abstract class DasocraticInfoPanel extends JPanel{

	protected DasocraticElement m_Element;
	protected MeigasPanel m_MeigasPanel;

	public DasocraticInfoPanel(DasocraticElement element, MeigasPanel panel){

		super();

		m_Element = element;
		m_MeigasPanel = panel;

		initializeContent();

		initGUI();

	}

	/*protected void commitEdit(JPanel panel){

		int i;
		Component[] components = panel.getComponents();
		for (i = 0; i < components.length; i++) {
	         if (components[i] instanceof JFormattedTextField){
	        	 try {
					((JFormattedTextField)components[i]).commitEdit();
				} catch (ParseException e) {}
	         }
	         else if (components[i] instanceof JPanel){
	        	 commitEdit((JPanel)components[i]);
	         }
	    }

	}*/

	protected abstract void initializeContent();
	protected abstract void updateContent();
	protected abstract boolean checkDataAndUpdate();
	protected abstract void initGUI();

	protected void removeListeners(){

		removeListeners(this);

	};

	protected void removeListeners(JPanel panel){

		int i;
		Component[] components = panel.getComponents();
		for (i = 0; i < components.length; i++) {
	         if (components[i] instanceof MeigasValueTextField){
				((MeigasValueTextField)components[i]).removeListener();
	         }
	         else if (components[i] instanceof JPanel){
	        	 removeListeners((JPanel)components[i]);
	         }
	    }
	}


}
